#include "queue.h"

int enQueue(queue_t* q,int net_fd)
{
    //构建新结点
    node_t* new_node=(node_t*)calloc(1,sizeof(node_t));
    new_node->net_fd=net_fd;

    if(q->size==0){
        q->head=new_node;
        q->rear=new_node;
    }else{
        q->rear->next=new_node;
        q->rear=new_node;
    }

    q->size++;

    return 0;
}

int deQueue(queue_t* q){
    if(q->size==0) return -1;

    node_t* p=q->head;
    q->head=p->next;

    if(q->size==1){
        q->rear=NULL;
    }

    q->size--;
    free(p);

    return 0;
}
    
